<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/9/9
  Time: 13:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>评分标准</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js?20200715.1" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/formdesign/bootstrap/js/bootstrap.js?20200826" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    .openFile input[type=file]{
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }
    .layui-text em, .layui-word-aux {
         color:red !important;
        padding: 0 5px !important;
    }
</style>
<body>
<div>
    <form class="layui-form" action="" style="margin: 10px;" lay-filter="ajaxforms">
        <div style="height: 30px;line-height: 30px;text-align: center;background: #f2f2f2;margin-bottom: 10px">基本信息</div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">任务名称</label>
                <div class="layui-input-inline">
                    <input type="tel" name="planName" id="planName" disabled lay-verify="required|phone" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">流水号</label>
                <div class="layui-input-inline">
                    <input type="text" name=""  disabled   lay-verify="email" autocomplete="off" class="layui-input serial">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">成果名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="topicName" id="topicName" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">成果类型<span style="color:red">*</span> </label>
                <div class="layui-input-inline">
                    <select name="topicType" id="dictName" lay-verify="required" lay-search="">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">注：成果类型不能重复，每个人只能报两个类别，<br>每个类别只能报一个，每个类别只能报一个成果</div>

            </div>
        </div>
       <%-- <div class="layui-form-item">
            <div class="layui-inline"></div>
            <div class="layui-inline">
            </div>
        </div>--%>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">申报人姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="userName" id="userName" disabled autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-inline">
                    <input type="tel" name="contactNumber"  id="contactNumber" lay-verify="required|phone" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">电子邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" name="postalCode"  id="postalCode" lay-verify="email" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">申报人科室</label>
                <div class="layui-input-inline">
                    <input type="text" name="deptName" id="deptName" disabled autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div style="height: 30px;line-height: 30px;text-align: center;background: #f2f2f2;margin-bottom: 10px">协作人员及在研究中承担的职务</div>
        <div class="layui-form-item">
            <tr>
                <td class="biwI" name="colspan" colspan="4" style="text-align: right;">
                    <div style="height: 30px"> <button name="plus" id="plus" type="button" class="layui-btn layui-btn-normal  layui-btn-sm" style="margin-left: 14px;float: right;margin-right:18px"><i class="layui-icon layui-icon-addition"></i> </button></div>
                </td>
            </tr>
            <tr>
                <td class="biwI" colspan="4" style="text-align: right;">
                    <div id="planTableDiv" class="layui-card-body">
                        <form action="" id="planTi">
                            <table class="layui-hide" id="demo1" lay-filter="demo1"></table>
                        </form>
                    </div>
                </td>
            </tr>
        </div>
        <div style="height: 30px;line-height: 30px;text-align: center;background: #f2f2f2;margin-bottom: 10px">成果简介</div>
        <div class="layui-form-item"  style="margin-top:15px">
            <label class="layui-form-label" style="width: 100px;margin-left:-20px;font-size: 20px;font-weight: 600">上传附件:</label>
            <div class="layui-input-inline">
                <div id="fujians"></div>
                <div id="fileAll">
                </div>
                <a href="javascript:;" class="openFile" style="float: left;margin-top:8px;position:relative">
                    <img src="../img/mg11.png" alt="" style="width: 18px;vertical-align: sub;">
                    <span style="font-size: 20px">添加附件</span>
                    <input type="file" multiple id="fileupload" data-url="/upload?module=fixAssets" name="file">
                </a>
            </div>
            <div class="layui-form-mid layui-word-aux">注：请上传成果附件及查重报告</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">成果简介</label>
            <div class="layui-input-block">
                <textarea  name="desc" class="layui-textarea desc"></textarea>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="planDel">
    <a class="layui-btn layui-btn-danger layui-btn-xs del2" lay-event="del2">删除</a>
</script>

<script>
    // 获取地址栏参数值
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    var planId = getQueryString('planId');
    var topicId = getQueryString('topicId');
    var type = getQueryString('type');
    var editUrl = getQueryString('edit')||'';
    var des = getQueryString('des');
    des = unescape(des);
    $('input[name="planName"]').val(des)
    $('.serial').val(planId)
    var table,form,laydate,upload,layedit;
    var ue;
    var userId;
    var trId15 = '';
    var trId16 = '';
    var tablePlus = [{
        trOther: ""
        ,trOther2: ''
        ,trOther3: ''
    }]

    //初始化加载
    $(function(){

        //渲染编辑器
        ue = UE.getEditor('container',{elementPathEnabled : false});

        //layui实例
        layui.use(['table', 'form', 'laydate','upload','layedit'], function () {
            table = layui.table,
                form = layui.form,
                laydate = layui.laydate,
                upload = layui.upload,
                layedit = layui.layedit;
            form.render();

            fileuploadFn('#fileupload', $('#fileAll'));

            //渲染表格
            table.render({
                elem: '#demo1'
                , data : tablePlus
                , page : false
                , cols : [[
                    {title: '序号',type:'numbers' , align: 'center' }
                    , {field: 'trOther', title: '协作人员', align: 'center',edit:true}
                    , {field: 'trOther2', title: '承担的职务', align: 'center',edit:true}
                    , {field: 'trOther3', title: '单位', align: 'center',edit:true}
                    ,{title: '操作',toolbar: '#planDel', align : 'center'}
                ]]
            });

            //第一实例监听工具事件
            table.on('tool(demo1)', function(obj) {
                var data = obj.data;
                var layEvent = obj.event;
                var tr = obj.tr;
                if(layEvent === 'del2'){
                    //删除等前行
                    var index = tr.attr("data-index");
                    obj.del(tr);
                }
            });

        });

        //加号按钮
        $(document).on('click', '#plus', function(){
            var demo1 = layui.table.cache["demo1"];
            var data1 = {
                trOther: ""
                ,trOther2:''
                ,trOther3:''
            };
            demo1.push(data1);
            table.reload('demo1', {
                data: demo1
            });
        });

        //删除附件
        $(document).on('click', '.deImgs', function () {
            var _this = this;
            var attUrl = $(this).parents('.dech').attr('deUrl');
            layer.confirm('确定删除该附件吗？', function (index) {
                $.ajax({
                    type: 'get',
                    url: '/delete?' + attUrl,
                    dataType: 'json',
                    success: function (res) {

                        if (res.flag == true) {
                            layer.msg('删除成功', {icon: 6, time: 1000});
                            $(_this).parent().remove();
                        } else {
                            layer.msg('删除失败', {icon: 2, time: 1000});
                        }
                    }
                })
            });
        });

        //回显  成果类型
        $.ajax({
            url:'/RpmDictonary/selectDictionaryByNo',
            dataType: 'json',
            type: 'get',
            data:{
                dictNo:'TYPE_OF_ACHIEVEMENT'
            },
            success: function (res) {
                var obj = res.data
                var str = ''
                for (var i = 0; i < obj.length; i++) {
                    str += '<option value="' + obj[i].dictNo + '">' + obj[i].dictName + '</option>'
                }
                $('#dictName').append(str);
                if(editUrl != ''){
                    $('#dictName').attr('disabled',true);
                }
                form.render('select');
            }
        })

        //回显操作
        if(type == "1"){
            $.ajax({
                url:'/Recognize/getRecogizeTopic',
                dataType: 'json',
                type: 'get',
                data:{
                    topicId:topicId
                },
                success: function (res) {
                    if (res.flag){
                        var obj = res.obj[0];
                        $('.desc').val(res.obj[0].desc)

                        //回显基础数据
                        form.val('ajaxforms', obj);
                        $("#planName").val(obj.rpmPlan.planName)
                        $("#dictName").val(obj.topicType)
                        var str = ''
                        if(obj.attachmentList == undefined){
                            str='';
                        }else if(obj.attachmentList.length>0){
                            for(var i=0;i<obj.attachmentList.length;i++){
                                str+='<div class="dech" deUrl="' +obj.attachmentList[i].attUrl + '"><a href="/download?' + obj.attachmentList[i].attUrl + '" NAME="' + obj.attachmentList[i].attachName +'*"><img style="margin-right:10px;" src="/img/attachment_icon.png"/>' + obj.attachmentList[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + obj.attachmentList[i].aid + '@' + obj.attachmentList[i].ym + '_' + obj.attachmentList[i].attachId +',"></div>'
                            }
                        }
                        $('#fujians').html(str);

                        //筛选type等于14的
                        var dataremark = [];
                        var remarkList=obj.remarkList
                        for (var i = 0; i <remarkList.length; i++) {
                            if (remarkList[i].trType == '14'){
                                dataremark.push(remarkList[i]);
                            }

                            //筛选type等于15的
                            if (remarkList[i].trType == '15'){
                                trId15 = remarkList[i].trId;
                            }

                            //筛选type等于15的
                            if (remarkList[i].trType == '16'){
                                trId16 = remarkList[i].trId;
                            }
                        }

                        //重载表格
                        table.reload('demo1', {
                            data:dataremark
                        });
                    }

                }
            })
        }else{
            //回显当前登录人
            $.get('/getLoginUser',function (res) {
                if (res.flag){
                    var object = res.object;
                    userId = object.userId;
                    $('#deptName').val(object.deptName);
                    $('#deptName').attr('deptid',object.deptId);
                    $('#userName').val(object.userName);
                }
            },'json');
        }

    });

    //成果列表保存
    function listSubmitEdit() {
        var regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;

        if($('#dictName').val()==''){
            layer.msg('请填写成果类型', {icon:2});
            return false
        }else if(!regs.test($('#contactNumber').val())){
            layer.msg('手机号码有误，请重填', {icon:2});

            return false;
        }

        var obj = {}
        var arr = []
        var demo1 = layui.table.cache["demo1"];
        for (var i = 0; i < demo1.length ; i++) {
            demo1[i]["trType"] = 14;
            demo1[i]["trRemark"] = '';
            demo1[i]["trStatus"] = '';
            demo1[i]["attachmentId"] = '';
            demo1[i]["attachmentName"] = '';
            demo1[i]["trTime"] = '';
            demo1[i]["trTopicId"] = topicId;
            arr.push(demo1[i]);
        }
        //附件
        var attachmentId = '';
        var attachmentName = '';
        for (var i = 0; i < $('#fileAll .dech').length; i++) {
            attachmentId += $('#fileAll .dech').eq(i).find('input').val();
            attachmentName += $('#fileAll a').eq(i).attr('name');
        }
        obj.planId = planId
        obj.topicId = topicId
        obj.planName = $('input[name="planName"]').val()
        obj.topicName = $("#topicName").val()
        obj.topicType = $('#dictName').val()
        obj.contactNumber = $("#contactNumber").val()
        obj.postalCode = $("#postalCode").val()
        obj.ctreateType=4
        obj.trJson= JSON.stringify(arr)
        obj.desc= $('.desc').val()
        obj.attachmentId = attachmentId
        obj.attachmentName=attachmentName;
        $.ajax({
            url: '/Recognize/updateTopicOrRemark',
            dataType: 'json',
            type: 'post',
            data: obj,
            success: function (res) {
                if (res.flag) {
                    parent.closes();
                }
            }
        })
    }

    // 成果列表保存并提交
    function listSubmitsave() {
        var regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;

        if($('#dictName').val()==''){
            layer.msg('请填写成果类型', {icon:2});
            return false
        }else if(!regs.test($('#contactNumber').val())){
            layer.msg('手机号码有误，请重填', {icon:2});

            return false;
        }

        var obj = {}
        var arr = []
        var demo1 = layui.table.cache["demo1"];
        for (var i = 0; i < demo1.length ; i++) {
            demo1[i]["trType"] = 14;
            demo1[i]["trRemark"] = '';
            demo1[i]["trStatus"] = '';
            demo1[i]["attachmentId"] = '';
            demo1[i]["attachmentName"] = '';
            demo1[i]["trTime"] = '';
            demo1[i]["trTopicId"] = topicId;
            arr.push(demo1[i]);
        }

        //主任的审批数据
        var obj2 =new Object();
        obj2["trId"] = trId15;
        obj2["trOther"] = '';
        obj2["trOther2"] = '';
        obj2["trOther3"] = '';
        obj2["trType"] = 15;
        obj2["trRemark"] = '';
        obj2["trStatus"] = 1;
        obj2["attachmentId"] = '';
        obj2["attachmentName"] = '';
        obj2["trTime"] = '';
        obj2["trTopicId"] = topicId;
        arr.push(obj2);

        //附件
        var attachmentId = '';
        var attachmentName = '';
        for (var i = 0; i < $('#fileAll .dech').length; i++) {
            attachmentId += $('#fileAll .dech').eq(i).find('input').val();
            attachmentName += $('#fileAll a').eq(i).attr('name');
        }
        obj.planId = planId
        obj.topicId = topicId
        obj.planName = $('input[name="planName"]').val()
        obj.topicName = $("#topicName").val()
        obj.topicType = $('#dictName').val()
        obj.topicType = $('#dictName').val()
        obj.contactNumber = $("#contactNumber").val()
        obj.postalCode = $("#postalCode").val()
        obj.ctreateType=4
        obj.trJson= JSON.stringify(arr)
        obj.desc= $('.desc').val()
        obj.attachmentId = attachmentId
        obj.attachmentName=attachmentName;

        $.post('/Recognize/updateTopicOrRemark',obj,function(res){
            if (res.flag) {
                parent.closes();
            }
        },'json');
    }

    //保存
    function submitEdit() {
        var regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;

        if($('#dictName').val()==''){
            layer.msg('请填写成果类型', {icon:2});
            return false
        }else if(!regs.test($('#contactNumber').val())){
            layer.msg('手机号码有误，请重填', {icon:2});

            return false;
        }

        var obj = {}
        var arr = []
        var demo1 = layui.table.cache["demo1"];
        for (var i = 0; i < demo1.length ; i++) {
            demo1[i]["trOther"] = $('td[data-field="trOther"] div').html();
            demo1[i]["trOther2"] = $('td[data-field="trOther2"] div').html();
            demo1[i]["trOther3"] = $('td[data-field="trOther3"] div').html();
            demo1[i]["trType"] = 14;
            demo1[i]["trRemark"] = '';
            demo1[i]["trStatus"] = '';
            demo1[i]["attachmentId"] = '';
            demo1[i]["attachmentName"] = '';
            demo1[i]["trTime"] = '';
            arr.push(demo1[i]);
        }
        //附件
        var attachmentId = '';
        var attachmentName = '';
        for (var i = 0; i < $('#fileAll .dech').length; i++) {
            attachmentId += $('#fileAll .dech').eq(i).find('input').val();
            attachmentName += $('#fileAll a').eq(i).attr('name');
        }
        obj.planId = planId
        obj.planName = $('input[name="planName"]').val()
        obj.topicName = $("#topicName").val()
        obj.promotionLeaderDept = $("#deptName").attr('deptid')
        obj.topicType = $('#dictName').val()
        obj.contactNumber = $("#contactNumber").val()
        obj.postalCode = $("#postalCode").val()
        obj.ctreateType=4
        obj.trJson= JSON.stringify(arr)
        obj.desc= $('.desc').val()
        obj.attachmentId = attachmentId
        obj.attachmentName=attachmentName;

        $.ajax({
            url: '/Recognize/insertRecogizeTopic',
            dataType: 'json',
            type: 'post',
            data: obj,
            success: function (res) {
                if(res.object=='0'){
                    layer.msg('成果类型重复', {icon:6});
                    return false
                }else{
                    if (res.flag) {
                        parent.closes();
                    }
                }
            }
        })
    }

    // 保存并提交
    function submitsave() {
        var regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;
        if($('#dictName').val()==''){
            layer.msg('请填写成果类型', {icon:2});
            return false
        }else if(!regs.test($('#contactNumber').val())){
            layer.msg('手机号码有误，请重填', {icon:2});

            return false;
        }

        var obj = {}
        var arr = []
        var demo1 = layui.table.cache["demo1"];
        for (var i = 0; i < demo1.length ; i++) {
            demo1[i]["trType"] = 14;
            demo1[i]["trRemark"] = '';
            demo1[i]["trStatus"] = '';
            demo1[i]["attachmentId"] = '';
            demo1[i]["attachmentName"] = '';
            demo1[i]["trTime"] = '';
            arr.push(demo1[i]);
        }

        //新增主任审核数据
        var obj2 =new Object();
        obj2["trOther"] = '';
        obj2["trOther2"] = '';
        obj2["trOther3"] = '';
        obj2["trType"] = 15;
        obj2["trRemark"] = '';
        obj2["trStatus"] = 1;
        obj2["attachmentId"] = '';
        obj2["attachmentName"] = '';
        obj2["trTime"] = '';
        arr.push(obj2);

        //新增秘书审核数据
       /* var obj3 =new Object();
        obj3["trOther"] = '';
        obj3["trOther2"] = '';
        obj3["trOther3"] = '';
        obj3["trType"] = 16;
        obj3["trRemark"] = '';
        obj3["trStatus"] = 1;
        obj3["attachmentId"] = '';
        obj3["attachmentName"] = '';
        obj3["trTime"] = '';
        arr.push(obj3);*/

        //附件
        var attachmentId = '';
        var attachmentName = '';
        for (var i = 0; i < $('#fileAll .dech').length; i++) {
            attachmentId += $('#fileAll .dech').eq(i).find('input').val();
            attachmentName += $('#fileAll a').eq(i).attr('name');
        }
        obj.planId = planId
        obj.planName = $('input[name="planName"]').val()
        obj.topicName = $("#topicName").val()
        obj.promotionLeaderDept = $("#deptName").attr('deptid')
        obj.topicType = $('#dictName').val()
        obj.contactNumber = $("#contactNumber").val()
        obj.postalCode = $("#postalCode").val()
        obj.ctreateType=4
        obj.trJson= JSON.stringify(arr)
        obj.desc= $('.desc').val()
        obj.attachmentId = attachmentId
        obj.attachmentName=attachmentName;
        $.ajax({
            url: '/Recognize/insertRecogizeTopic',
            dataType: 'json',
            type: 'post',
            data: obj,
            success: function (res) {
                if(res.object=='0'){
                    layer.msg('成果类型重复', {icon:6});
                    return false
                }else{
                    if (res.flag) {
                        parent.closes();
                    }
                }
            }
        })
    }

</script>
</body>
</html>
